home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
bipl.zip
/
PROCS.ZIP
/
ESCAPE.ICN
< prev
next >
Wrap
Text File
|
1992-11-24
|
2KB
|
90 lines
############################################################################
#
# File: escape.icn
#
# Subject: Procedures to interpret Icon literal escapes
#
# Authors: William H. Mitchell; modified by Ralph E. Griswold, and
# Alan Beale
#
# Date: November 24, 1992
#
###########################################################################
#
# The procedure escape(s) produces a string in which Icon quoted
# literal escape conventions in s are replaced by the corresponding
# characters. For example, escape("\\143\\141\\164") produces the
# string "cat".
#
############################################################################
#
# Links: ebcdic
#
############################################################################
link ebcdic
procedure escape(s)
local ns, c
ns := ""
s ? {
while ns ||:= tab(upto('\\')) do {
move(1)
ns ||:= {
c := map(move(1)) | break
case c of {
"b": "\b"
"d": "\d"
"e": "\e"
"f": "\f"
"l": "\n"
"n": "\n"
"r": "\r"
"t": "\t"
"v": "\v"
"'": "'"
"\"": "\""
"x": hexcode()
"^": ctrlcode()
!"01234567": octcode()
default: c
}
}
}
ns ||:= tab(0)
}
return ns
end
procedure hexcode()
local i, s
static hdigits
initial hdigits := ~'0123456789ABCDEFabcdef'
move(i := 2 | 1) ? s := tab(upto(hdigits) | 0)
move(*s - i)
return char("16r" || s)
end
procedure octcode()
local i, s
static odigits
initial odigits := ~'01234567'
move(-1)
move(i := 3 | 2 | 1) ? s := tab(upto(odigits) | 0)
move(*s - i)
if s > 377 then { # back off if too large
s := s[1:3]
move(-1)
}
return char("8r" || s)
end
procedure ctrlcode(s)
return Control(move(1))
end